package com.gelsanalyzer.ui.swing;

import java.awt.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

import com.gelsanalyzer.business.*;
import com.gelsanalyzer.business.control.*;
import com.gelsanalyzer.ui.swing.command.*;

public class CourseEntryPanel extends JPanel {

    public CourseEntryPanel(String studentID, Handler handler) {
        makeTheObjects(studentID, handler);
        doTheLayout();
    }

    // make all the objects
    private void makeTheObjects(String studentID, Handler handler) {
        // first things first... assign this JPanel a handler
        this.handler = handler;

        // column names for table
        //String[] columnNames = { "Department", "Course", "Goal(s)" };

        //theJFrame = new JFrame();
        addCourseButton = new JButton("Add Course");
        addCourseButton.setEnabled(false);

        // can also addItem() to add to comboBox
        courseNums = new CourseNumComboCommand(this, handler);
        courseNums.setEnabled(false);

        departments = new DepartmentComboCommand(handler, courseNums);

        studentLabel = new JLabel("Student ID");
        departmentLabel = new JLabel("Department");
        courseLabel = new JLabel("Course");

        CourseEntryList cel = new CourseEntryList();
        // JTable(Object[][] rowData, Object[] columnNames); need to add rowData
        courseTable = new JTable(cel);
        cel.addTableModelListener(new TableModelListener() {
            public void tableChanged(TableModelEvent e) {             
                AbstractTableModel temp = (AbstractTableModel) e.getSource();                
            }
        });
        
        //table can not be edited
        //courseTable.removeEditor();

        // put table in scrolling pane
        tablePane = new JScrollPane(courseTable);

        studentId = new JTextField(studentID);
        studentId.setEditable(false);
    }

    // Layout all the objects
    private void doTheLayout() {
        leftPanel = new JPanel();
        rightPanel = new JPanel();

        // layout left side
        leftPanel.setLayout(new GridLayout(7, 2, 5, 5));
        leftPanel.add(studentLabel);
        leftPanel.add(studentId);
        leftPanel.add(departmentLabel);
        leftPanel.add(departments);
        leftPanel.add(courseLabel);
        leftPanel.add(courseNums);
        leftPanel.add(new JLabel());
        leftPanel.add(new JLabel());
        leftPanel.add(new JLabel());
        leftPanel.add(new JLabel());
        leftPanel.add(new JLabel());
        leftPanel.add(new JLabel());
        leftPanel.add(addCourseButton);

        // layout right side panel
        rightPanel.add(tablePane);

        // layout GUI
        setLayout(new BorderLayout());
        add(leftPanel, "West");
        add(rightPanel, "East");
    }

    public JButton getAddCourseButton() {
        return addCourseButton;
    }

    public JComboBox getDepartments() {
        return departments;
    }

    public JComboBox getCourseNums() {
        return courseNums;
    }
    
    public JTable getCourseTable() {
        return courseTable;
    }

    // Variables declaration
    private javax.swing.JButton addCourseButton;
    private DepartmentComboCommand departments;
    private CourseNumComboCommand courseNums;
    private javax.swing.JLabel studentLabel;
    private javax.swing.JLabel departmentLabel;
    private javax.swing.JLabel courseLabel;
    private javax.swing.JPanel leftPanel;
    private javax.swing.JPanel rightPanel;
    private javax.swing.JScrollPane tablePane;
    private javax.swing.JTable courseTable;
    private javax.swing.JTextField studentId;
    private Handler handler;
    // End of variables declaration

}
